|
|
|
|
|
|
|
You can see that Listing 19.8 performs the same three functions as ODBCConnect, only this time in reverse. First, it releases the statement handle, and then it performs the actual disconnect of the ODBC interface. Finally, the routine releases the connection handle. |
|
|
|
|
|
|
|
|
Of course, you need a routine to release the environment handle, too. Create the DeallocateEnv function and enter the code in Listing 19.9. |
|
|
|
|
|
|
|
|
Listing 19.9. Coding the DeallocateEnv function. |
|
|
|
|
|
|
|
|
Private Function DeallocateEnv()
'
' Frees specified env. handle
' clears stored in hEnv property
'
Dim intResult As Integer
'
If hEnv <> 0 Then
intResult = SQLFreeEnv(hEnv)
If intResult <> sqlSuccess Then
Err.Raise vbObjectError + 2, App.EXEName, "Unable to free environ
ment handle"
DeallocateEnv = intResult
Exit Function
End If
End If
'
DeallocateEnv = sqlSuccess
'
End Function |
|
|
|
|
|
|
|
|
Listing 19.9 is a simple routine. It tells the ODBC interface that you are done with the session and returns any resulting codes. |
|
|
|
|
|
|
|
|
The last mid-level routine you need is an ODBC error routine. This routine gathers any error information sent to your Visual Basic program from the ODBC data source. ODBC data sources are capable of sending more than one line of error information. For this reason, you write the routine as a loop that continues to ask for error messages until there are none to be found. |
|
|
|
|
|
|
|
|
Create a new Public Sub called sqlErrorMsg and enter the code in Listing 19.10. |
|
|
|
|
|
|
|
|
Listing 19.10. Coding the sqlErrorMsg subroutine. |
|
|
|
|
|
|
|
|
Public Sub sqlErrorMsg(strMsg As String)
'
' report detailed SQL Error
'
Dim strSQLState As String * 16 |
|
|
|
|
|